using System;
using System.Collections.Generic;
using System.Text;

namespace Tortuga.Core.TortoiseCommands {
	/// <summary>
	/// Saves a file from an URL or working copy path given in /path to the 
	/// location given in /savepath:path. The revision is given in /revision:xxx. 
	/// This can be used to get a file with a specific revision.
	/// http://tortoisesvn.net/docs/nightly/TortoiseSVN_en/apc.html
	/// </summary>
	public class CatCommand : SinglePathTortoiseCommand {
		public CatCommand() : this("") { }
		public CatCommand(string path)
			: base("cat", path) {
			this.OptionsToBuild = new List<BuildOptionDelegate>(new BuildOptionDelegate[] {
				this.BuildPathOption,
				this.BuildRevision,
				this.BuildSavePath,
				this.BuildNoTempFile,
				this.BuildCloseOnEnd
			});					
		}

		private Revision _revision = Revision.Head;
		private string _savePath = "";

		/// <summary>
		/// Gets or sets the Revision to be retrieved.
		/// </summary>
		public Revision Revision {
			get { return _revision; }
			set { _revision = value; }
		}


		/// <summary>
		/// Gets or sets the path to where this file should be saved
		/// </summary>
		public string SavePath {
			get { return _savePath; }
			set { _savePath = value; }
		}

		/// <summary>
		/// Builds the save path based on the current SavePath value.
		/// </summary>
		/// <returns></returns>
		public string BuildSavePath() {
			return BuildSavePath(this.SavePath);
		}

		/// <summary>
		/// Builds the savepath
		/// </summary>
		/// <param name="path">The path to where this file should be saved</param>
		/// <returns></returns>
		public static string BuildSavePath(string path) {
			return BuildOption("savepath", path);
		}

		/// <summary>
		/// Builds the revision option.
		/// </summary>
		/// <returns></returns>
		public string BuildRevision() {
			return BuildRevision(this.Revision);
		}

		/// <summary>
		/// Builds the revision option.
		/// </summary>
		/// <param name="rev">The desired revision</param>
		/// <returns></returns>
		public static string BuildRevision(Revision rev) {
			return BuildRevisionOption(rev, "revision");
		}
	}
}